import * as types from '../types'
import {http} from '@/utils/http'
export default {
	// 获取商家所有菜单数据
	foodMenu({dispatch},id){
		return http.get(`shop/${id}/productList`)
		.then(({data})=>{
			if(data.status == 200){
				dispatch('getProductList',data.data)
				return Promise.resolve(data.data)
			}
		}).catch(err=>{
			console.log(err)
		})
	},
	// 获取分类所有商品数据
	getProductList({
		commit
	},payload) {
		commit(types.GET_PRODUCT_LIST, payload)
	},
	// 加入购物车
	addToCart({commit},{payload,shopId}){
		commit(types.ADD_TO_CART,{id:payload.id,categoryType:payload.categoryType,shopId:shopId})
	},
	// 移除购物车
	removeToCart({commit},{payload}){
		commit(types.REMOVE_TO_CART,{id:payload.id,categoryType:payload.categoryType})
	},
	// 初始化购物车信息。从服务器调用
	initCart({commit},{payload}){
		commit(types.INIT_CART_INFO,{payload:payload})
	},
	// 商家信息
	onShopInfo({commit},payload){
		commit(types.SHOP_INFO,payload)
		return Promise.resolve(payload)
	},
	// 用餐人数
	setNum({commit},payload){
		commit(types.SET_NUM,payload)
	},
	setCoupon({commit},payload){
		commit(types.SET_COUPON,payload);
	}
}